package com.lantosec.hmrp.modules.monitor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lantosec.hmrp.core.util.MonitorUtils;
import com.lantosec.hmrp.modules.monitor.entity.CoreIndexEntity;
import com.lantosec.hmrp.modules.monitor.mapper.MonitorCoreIndexMapper;
import com.lantosec.hmrp.modules.monitor.service.IMonitorCoreIndexService;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service()
@Primary
@Log4j2
@SuppressWarnings("all")
public class MonitorCoreIndexServiceImpl extends ServiceImpl<MonitorCoreIndexMapper, CoreIndexEntity> implements IMonitorCoreIndexService {
    @Override
    public List<CoreIndexEntity> getCoreIndexList(String month, Integer year) {
        String startTime = MonitorUtils.getLastMonth();
        String endTime = MonitorUtils.getTbDate(startTime);
        List<CoreIndexEntity> param = null;
        if(StringUtils.isNotEmpty(month)){
            endTime = MonitorUtils.getTbDate(month);
            param = baseMapper.getMonthData(month,endTime);
        }else if(null != year){
            endTime = String.valueOf(year - 1);
            param = baseMapper.getYearData(year,endTime);
        }else{
            endTime = MonitorUtils.getTbDate(startTime);
            param = baseMapper.getMonthData(startTime,endTime);
        }
        return param;
    }

    @Override
    public List<CoreIndexEntity> getCoreIndexDetails(String month, String year, String colName) {
        List<CoreIndexEntity> param = null;
        if(StringUtils.isNotEmpty(month)){
            param = baseMapper.getMonthDetails(colName);
        }else if(StringUtils.isNotEmpty(year)){
            param = baseMapper.getYearDetails(colName);
        }
        return param;
    }
}
